package IO;

import java.io.*;
//拷贝一个普通文本文档
public class ReadAndWriter {
    public static void main(String[] args) {
        FileReader reader =null;
        FileWriter writer =null;
        try {//创建读写对象
            reader =new FileReader("D:\\BanGong\\TestFile\\temm.txt");
            writer =new FileWriter("D:\\BanGong\\TestFile\\temm-副本.txt");
            //边读边写
            char[] chars =new char[1024*1024];
            int readCount =0;
            while((readCount = reader.read(chars))!=-1){
                writer.write(chars,0,readCount);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch(IOException e){
            e.printStackTrace();
        }finally{
            if(reader !=null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (writer !=null){
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
